package cn.hsa.xxx.bookData.controller;


import cn.hsa.hsaf.core.framework.HsafController;
import cn.hsa.hsaf.core.framework.web.WrapperResponse;
import cn.hsa.xxx.api.dto.BookInfoDTO;
import cn.hsa.xxx.api.service.BookInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/web/bookData/bookInfo")
@RestController
@Slf4j
public class BookInfoController extends HsafController {

    @Autowired
    private BookInfoService bookInfoService;

    @PostMapping("/addBook")
    public WrapperResponse<BookInfoDTO> addBook(@RequestBody BookInfoDTO bookInfoDTO) {
        BookInfoDTO result = bookInfoService.add(bookInfoDTO);
        return WrapperResponse.success(result);
    }

    @GetMapping("/getBook")
    public WrapperResponse<BookInfoDTO> getBook(@RequestParam String id) {
        log.debug("请求参数：id={}", id);
        BookInfoDTO result = bookInfoService.get(id);
        return WrapperResponse.warning(321123, "警告：一些信息", result);
    }


    /**
     * 获取一页用户数据
     */
    @GetMapping("/page")
    public WrapperResponse<List<BookInfoDTO>> getPageBooks(int pageNo, int pageSize) {
        List<BookInfoDTO> bookInfoDTOList = bookInfoService.getPage(pageNo, pageSize);
        return WrapperResponse.info(324321, "提示：一些信息", bookInfoDTOList);

    }

//    @Resource
//    private BookInfoDAO bookInfoDAO;
//
//    @GetMapping("/test")
//    public List<BookInfoDO> getAll() {
//        List<BookInfoDO> allBooks = bookInfoDAO.getAllBooks();
//        return allBooks;
//    }




}
